package com.ericcson.innerportalapp;

import java.util.ArrayList;

import com.ericcson.innerportalapp.OfficeListFragment.OnGetOfficeList;
import android.os.Bundle;
import android.app.ActionBar;
import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;

public class OfficeLocationActivity extends Activity implements OnGetOfficeList {
	
	private OfficeListFragment officeListFragment;
	private OfficeListArrayAdapter officeListArrayAdapter;
	
	private ArrayList<Office> officeList = new ArrayList<Office>() {/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

	{
		add(new Office("Izmir Office", 27.206369, 38.366462));
		add(new Office("Ankara Office", 32.839284, 39.934447));
		add(new Office("Istanbul Office", 32.867927, 39.957544));
		
		
	}};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_office_location);
		
		FragmentManager fm = getFragmentManager();

		officeListFragment = (OfficeListFragment) fm
				.findFragmentById(R.id.office_list_container);
		if (officeListFragment == null) {
			officeListFragment = new OfficeListFragment();

			FragmentTransaction ft = fm.beginTransaction();
			ft.add(R.id.office_list_container, officeListFragment);
			ft.commit();
		}
		
		ActionBar ab = getActionBar();
        ab.setDisplayHomeAsUpEnabled(true);
        ab.setTitle("Office Location");
        ab.setIcon(R.drawable.ic_action_place);
		
		officeListArrayAdapter = new OfficeListArrayAdapter(this,
				R.layout.office_list_item, officeList);
		officeListFragment.setListAdapter(officeListArrayAdapter);
		
	}

//	@Override
//	public boolean onCreateOptionsMenu(Menu menu) {
//		// Inflate the menu; this adds items to the action bar if it is present.
//		getMenuInflater().inflate(R.menu.office_location, menu);
//		return true;
//	}

	@Override
	public ArrayList<Office> getOfficeList() {
		return officeList;
	}

}
